<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%  
response.setHeader("Access-Control-Allow-Origin", "*");  
%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据源·思通投研·让数据驱动投资价值!</title>
	<link href="${pageContext.request.contextPath }/img/webLogoIcon.png" rel="shortcut icon">
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/font-awesome.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath }/css/style.css" rel="stylesheet">
    <!-- FooTable -->
    <link href="${pageContext.request.contextPath }/css/footable.core.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/css/mypage.css" rel="stylesheet">
    <style>
		.select2_demo_1{
			float: left;
			width: 120px;
			display: inline;
			margin-left: 10px;
		}
		.form-control{
			display: inline;
		}
		
		.col-sm-3{
			float:right;
			width: 560px;
		}
		.input-group{
			float:right;
			width: 240px;
			margin-left: 5px;
		}
	   td{
	        vertical-align:middle;
	    }
	    .source{
	    	display:inline-block;
	        cursor: pointer;
		   	margin-bottom: 10px;
		    padding: 5px 5px;
		    border: 1px solid #ccc;
		    border-radius: 4px;
		    margin-right: 20px;
   		}
   		.sourceAct{
   			border-color:#f8ac59;
   			color:#f8ac59;
   		}
   		.webAct{
   			border-color:#f8ac59 !important;
   			color:#f8ac59;
   		}
   		.web{
	    	display:inline-block;
	        cursor: pointer;
		   	margin-bottom: 10px;
		    padding: 5px 5px;
		    border: 1px solid #ccc;
		    border-radius: 4px;
		    margin-right: 20px;
   		}
	</style>
</head>
<body>
    <div id="wrapper">
        <nav class="navbar-default navbar-static-side" role="navigation">
            <%request.setAttribute("LEFT", "datasource");%>
            <%@include file="left-factory.jsp"%>
        </nav>
        <div id="page-wrapper" class="gray-bg">
        <div class="row border-bottom">
		<jsp:include page="head-factory.jsp" flush="true" />
        </div>
        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-9">
                <h2>数据源</h2>
                <ol class="breadcrumb">
                	<li class="nav-main1">
                		<a href="${pageContext.request.contextPath}/admin/tosystem_overview">主页</a>
                	</li>
                	<li class="nav-main2" >
                		<a id="navigation1" href="#" >媒体资讯</a>
                	</li>
                	<li class="active">
                		<a>数据源</a>
                	</li>
               	</ol>
            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <div class="row" style="font-size: 16px;margin-top: 2%;padding: 0 30px;" id="data-source">
<!--                                 <div class="col-lg-3"> -->
<!--                                     <dl class="dl-horizontal"> -->
<!--                                     	<dt>状态:</dt> -->
<!--                                         <dt>创建时间:</dt> -->
<!--                                         <dt>创建时间:</dt> -->
<!--                                     </dl> -->
<!--                                 </div> -->
                            </div>
                            <div class="puisne" style="font-size: 16px;margin-top: 2%;padding: 0 30px;" id="data-puisne">
								<span onclick="website(this)" data-type=0 class="sourceAct" id="webAct">全部</span>
                            </div>
                            <div class="row m-t-sm">
                                <div class="col-lg-12">
                                <div class="panel blank-panel">
                                <div class="panel-heading">
                                    <div class="panel-options">
                                        <ul class="nav nav-tabs">
                                            <li class="active"><a href="#tab-1" data-toggle="tab">文章列表</a></li>
                                            <li class="active"><div class="select">
                                            					<select class="form-control" id="time" onchange="timeseek()">
                                            					<option value="" ${time == 1? 'selected':'' }>全部</option>
										                    	<option value="1" ${time == 1? 'selected':'' }>24小时</option>
										                    	<option value="2" ${time == 2? 'selected':'' }>7天</option>
										                    	<option value="3" ${time == 3? 'selected':'' }>30天</option>
										                    	</select>
										                    	</div>
						                    </li>
						                    <li><input class="select-text" value="" id="website_name" placeholder="搜索文章"></li>
                    						<li><button class="btn btn-primary" onclick="timeseek()">搜索</button></li>
                                        </ul>
                                    </div>
                                </div>
                                <div class="panel-body">
                                <div class="tab-content">
                                <div class="tab-pane active" id="tab-1">
                                
                                    <div class="feed-activity-list" id="list">
<!--                                         <div class="feed-element"> -->
<!--                                            <div class="search-result"> -->
<!--                                            		<h3><a target="_blank" href="">title</a></h3> -->
<!--                                            		<br /> -->
<!--                                            		<p>content</p> -->
<!--                                            		<p> -->
<!--                                            			<span>来源: </span> -->
<!--                                            			<span style="float: right; margin-right: 30px;">时间:</span> -->
<!--                                            		</p> -->
<!--                                            </div> -->
<!--                                         </div> -->
                                    </div>
                                    <div class="feed-activity-list" id="logs">
                                    	<div class="box" id="box" style="float: right;"></div>
                                    </div>
                                </div>
                                </div>
                                </div>
                                </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
        </div>
        </div>
		<jsp:include page="footer.jsp" flush="true" />
        </div>
        </div>
    <!-- Mainly scripts -->
    <script src="${pageContext.request.contextPath }/js/jquery-2.1.1.js"></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/jquery.metisMenu.js"></script>
    <script src="${pageContext.request.contextPath }/js/jquery.slimscroll.min.js"></script>
    <!-- Custom and plugin javascript -->
    <script src="${pageContext.request.contextPath }/js/inspinia.js"></script>
    <script src="${pageContext.request.contextPath }/js/pace.min.js"></script>
    <!-- FooTable -->
    <script src="${pageContext.request.contextPath }/js/footable.all.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/mypage.js"></script>
    <!-- Page-Level Scripts -->
    <script>
    var pageNum="1";
    var websiteclassify = "";
    var onSearch = false
    
    function timeseek(pageNum){
    	var time=document.getElementById("time").value;
    	var keyword=document.getElementById("website_name").value;
    		$.ajax({
    			type:'post',
    			url:"${basePath}/spider-factory/data-source/lowersite",
    			data:{
    				time:time,
    				keyword:keyword,
    				sitename: websiteclassify,
    				pageNum:pageNum
    			},
    			dataType:"json",
    			success:function(res){
    				$('#list').html('')
    				res = JSON.parse(res)
    				var totalData =res.count
    				var bbb=$(".webAct").attr("data-type")
    				console.log(websiteclassify,"+++++++++++++++",bbb);
					var totalPage =res.page_count
					if(totalData>5000){
						totalData = "5000";
						totalPage = "500";
					}
    				paging(totalData, totalPage, pageNum)
    				console.log(res,"________")
    				var size=res.data.length
    				var datamun = 5555
    				
    				if(onSearch){
    				changeNum(bbb,datamun)
    				}
    				
    				for(var i=0;i<size;i++){
    					var data=res.data[i]._source
    					var content = data.content
        				if (content.length - 300 > 0) {
        					content = content.substring(0, 300) + '......'
						}
    					var html = '<div class="feed-element">'+
			                        ' <div class="search-result">'+
				                		'<h3><a target="_blank" href="'+data.source_url+'">'+data.title+'</a></h3>'+
				                		'<br />'+
				                		'<p>'+content+'</p>'+
				                		'<p>'+
				                			'<span>来源:'+data.sourcewebsitename+'</span>'+
				                			'<span style="float: right; margin-right: 30px;">时间:'+data.publish_time+'</span>'+
			                			'</p>'+
			                		'</div>'+
			                	' </div>'
					  $('#list').append(html)
					  
					  
    				}
    				if (size == 0) {
        				$('#list').html('<div class="feed-element">暂无数据！</div>')
					}
    			},
    			error:function(res){
    				$('#list').html('<div class="feed-element">暂无数据！</div>')
    			}
    			
    		})
    	
    }
    
    
    function changeNum(bbb,datamun) {
    	var datacon =bbb+':'+datamun
		$(".webAct").html(datacon)
	}
    
    
    function website(id){
    	$(id).addClass('webAct')
    	$(id).siblings().removeClass('webAct')
    	websiteclassify = $(id).attr('data-type')
    	timeseek(1);
    	onSearch = false;
    };
    
        $(document).ready(function() {
            $('.footable').footable();
        });
        
        $(function(){
        	dataSourceCount()
        	aaaa(1)
		});
        
        var classify = '1'
        
        function query(obj){
        	$(obj).addClass('sourceAct')
        	$(obj).siblings().removeClass('sourceAct')
        	
        	classify = $(obj).attr('data-type')
        	aaaa(1)
        }
        
		function dataSourceCount(){
        	$.ajax({
        		url : "${pageContext.request.contextPath}/data-source/dataSourceCount",
        		type : "post",
        		data: { },
        		async: false,
        		success : function(res) {
        			$('#data-source').html('')
        			res = JSON.parse(res)
        			var list = res.list
        			for (var i = 0; i < list.length; i++) {
        				var html = ''
        				if (i == 0) {
        					classify = list[i].key
        					html = '<span onclick="query(this)" data-type='+list[i].key+' class="source sourceAct">'+list[i].name+':'+list[i].doc_count+'</span>'
						}else {
							html = '<span onclick="query(this)" data-type='+list[i].key+' class="source">'+list[i].name+':'+list[i].doc_count+'</span>'
						}
					    $('#data-source').append(html)
					}
        		}
        	});
        }
        
        function paging(totalData,totalPage, pagenum) {
        	
			$('#box').paging({
				initPageNo : pagenum, // 初始页码
				totalPages : totalPage, //总页数
				totalCount : '合计' + totalData + '条数据', // 条目总数
				slideSpeed : 600, // 缓动速度 单位毫秒
				jump : true, //是否支持跳转
				callback : function(page) { // 回调函数 
					}
			});
		}
        
		function JumpToPage(pageNum) {
		
			if(websiteclassify != null && websiteclassify!=""){
				timeseek(pageNum);
			}else{
				aaaa(pageNum)
			}
			
		}
		
		function aaaa(pageNum){
        	$.ajax({
        		url : "${pageContext.request.contextPath}/data-source/article",
        		type : "post",
        		data:{
        			classify: classify,
        			pageNum: pageNum
        		},
        		success : function(res1) {
        			$('#list').html('')
        			$('#data-puisne').html('')
        			let res = JSON.parse(res1);
        			paging(res.totalData, res.totalPage, pageNum)
        			var list = res.list
        			var level = res.level
        		
        			
        			
        			for(var n=0;n<level.length;n++){
        				var key = level[n].key
        				var count = level[n].doc_count
        				
        				var puisne='<span onclick="website(this)" data-type='+key+' class="web">'+key+':'+count+'</span>';
        				$('#data-puisne').append(puisne)
        			}
        			
        			for (var i = 0; i < list.length; i++) {
        				var content = list[i].content
        				if (content.length - 300 > 0) {
        					content = content.substring(0, 300) + '......'
						}
						var html = '<div class="feed-element">'+
					                           ' <div class="search-result">'+
					                   		'<h3><a target="_blank" href="'+list[i].source_url+'">'+list[i].title+'</a></h3>'+
					                   		'<br />'+
					                   		'<p>'+content+'</p>'+
					                   		'<p>'+
					                   			'<span>来源:'+list[i].sourcewebsitename+'</span>'+
					                   			'<span style="float: right; margin-right: 30px;">时间:'+list[i].publish_time+'</span>'+
					                   		'</p>'+
					                   '</div>'+
					               ' </div>'
					     $('#list').append(html)
					}
        			if (list.length == 0) {
        				$('#list').html('<div class="feed-element">暂无数据！</div>')
					}
        		},
        		error: function(res) {
        			$('#list').html('<div class="feed-element">暂无数据！</div>')
        		}
        	});
        }
		
		//跑马灯方法 
// 		 function init(){
// 			    //获取标题
// 			    var title=document.title;
// 			    //分割字符串--->字符数组
// 			    var arr=title.split("");
// 			    //删除第一个元素并返回该元素
// 			    var e=arr.shift();
// 			    //把一个对象添加到数组末尾
// 			    arr.push(e);
// 			    //把数组转换成字符串
// 			    var marquee=arr.join("");
// 			    //返回给浏览器
// 			    document.title=marquee;
// 			    //定时一直执行
// 			    window.setTimeout("init()",1000);
// 			}
// 			window.onload=init;
    </script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
</body>
</html>
